<template>
  <el-table
    :data="tableData"
    border
    style="width: 100%"
    :row-key="(row)=>''+row.id + (row.index+1)*(Math.random()+1)+row.type"
    :tree-props="{children: 'tasks'}">
    <el-table-column
      type="index"
      width="50">
    </el-table-column>
    <el-table-column
      prop="project_name"
      label="名称"
      width="180">
      <template v-slot="{row}">
        {{ row.project_name || row.type }}
      </template>
    </el-table-column>
    <el-table-column
      prop="device_count"
      label="数量"
      width="180"
    >
      <template v-slot="{row}">
        {{ row.device_count === undefined ? test(row) : row.device_count }}
      </template>
    </el-table-column>
    <el-table-column
      prop="plan_work_hour"
      label="计划工时">
    </el-table-column>
    <el-table-column
      prop="work_hour"
      label="实际工时"
    ></el-table-column>
    <el-table-column
      v-for="m in MDate"
      :label="m"
      :key="m"
      width="100"
    >
      <template v-slot="{row}">
        {{ judgmentDate(row, m) }}
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
export default {
  name: "report-table",
  props: ["tableData", "MDate"],
  data() {
    return {}
  },
  methods: {
    judgmentDate(row, key) {
      if (row?.items === undefined) return ""
      return row.items[key]
    },
    test(row) {
      if (row?.items === undefined) return "1111"
      let total = 0
      for (let item in row.items) {
        total += row.items[item]
      }
      return total
    },
  }
}
</script>

<style scoped>

</style>
